home *** CD-ROM | disk | FTP | other *** search
Java Source | 1996-05-23 | 25.9 KB | 959 lines |
- // FileBrowserComponent
- // A JFS application for copying, deleting and moving files on a JFS filesystem.
- // Also has the ability to launch other JFS programs for viewing and editing
- // files.
- import java.awt.*;
- import java.io.IOException;
- import java.util.Vector;
- import java.util.Date;
-
- public class FileBrowserComponent extends JFScomponent
- {
- java.applet.Applet ap; // applet we are in
- DoubleListPanel files; // file list box
- DoubleListPanel versions; // version list box
- DoubleListPanel users; // users list box
- Button pathb; // refresh button
- TextField dir; // current directory
- Button parb; // parent button
- TextField file; // current file
- Button vdelb; // delete version button
- Button vpurb; // renumber version button
- Button vinfob; // version info button
- Button uaddb; // add user button
- Button udelb; // delete user button
- Button uinfob; // user info button
- Button frunb; // program run button
- Button fopenb; // file open button
- Button fdelb; // file delete button
- Button fcopyb; // file copy button
- FilenameReq copyreq; // copy file requestor
- Button frenb; // file rename button
- FilenameReq renreq; // rename file requestor
- Button fmkdirb; // make directory button
- FilenameReq mkdirreq; // make directory requestor
- Button fprintb; // file print button
- Button fchtypeb; // change type button
- FilenameReq chtypereq; // new MIME type requestor
-
- JFSdirectory current; // current dir
- Vector filesinfo = new Vector();// info about files in list
- Vector versionsinfo = new Vector();
- Vector usersinfo = new Vector();
-
- void init(java.applet.Applet a)
- {
- ap = a;
- Color hi = new Color(220, 220, 220);
- Color lo = new Color(50, 50, 50);
- setLayout(new BorderLayout());
-
- // create bottom buttons
- Panel bot = new SpacedPanel(0,3);
- bot.setLayout(new FlowLayout(FlowLayout.LEFT));
- bot.add(frunb = new Button("Run"));
- bot.add(fopenb = new Button("Open"));
- bot.add(fdelb = new Button("Delete"));
- bot.add(fcopyb = new Button("Copy"));
- bot.add(frenb = new Button("Rename"));
- bot.add(fmkdirb = new Button("Make dir"));
- bot.add(fprintb = new Button("Print"));
- bot.add(fchtypeb = new Button("MIME"));
- add("South",bot);
-
- // create file list
- Panel top = new Panel();
- top.setLayout(new GridLayout(1,2));
- Panel left = new SpacedPanel(3,0);
- left.setLayout(new BorderLayout());
- Panel dirpanel = new SpacedPanel(0,3);
- dirpanel.setLayout(new BorderLayout());
- dirpanel.add("West",pathb = new Button("Path :"));
- dirpanel.add("Center",dir = new TextField("/"));
- dirpanel.add("East",parb = new Button("Parent"));
- dir.setEditable(false);
- left.add("North",dirpanel);
- Panel filepanel = new SpacedPanel(0,3);
- filepanel.setLayout(new BorderLayout());
- filepanel.add("West",new Label("File :"));
- filepanel.add("Center",file = new TextField());
- file.setEditable(false);
- left.add("South",filepanel);
- left.add("Center",files = new DoubleListPanel("Name","Type"));
- top.add(left);
-
- // create version list
- Panel right = new Panel();
- right.setLayout(new GridLayout(2,1));
- Panel verpanel = new SpacedPanel(0,3);
- verpanel.setLayout(new BorderLayout());
- Panel vpbot = new Panel();
- vpbot.setLayout(new GridLayout(1,3));
- vpbot.add(vdelb = new Button("Delete"));
- vpbot.add(vpurb = new Button("Purge"));
- vpbot.add(vinfob = new Button("Info"));
- verpanel.add("South",vpbot);
- verpanel.add("Center",versions = new DoubleListPanel("Version","Size"));
- verpanel.add("North",new Label("Versions"));
- right.add(verpanel);
-
- // create users list
- Panel usrpanel = new SpacedPanel(0,3);
- usrpanel.setLayout(new BorderLayout());
- Panel upbot = new Panel();
- upbot.setLayout(new GridLayout(1,3));
- upbot.add(uaddb = new Button("Add"));
- upbot.add(udelb = new Button("Delete"));
- upbot.add(uinfob = new Button("Info"));
- usrpanel.add("South",upbot);
- usrpanel.add("Center",users = new DoubleListPanel("Name","Access"));
- usrpanel.add("North",new Label("Permissions"));
- right.add(usrpanel);
- top.add(right);
- add("Center",top);
- }
-
- // fillfiles
- // Fill the files window with files from the current directory
- void fillfiles()
- {
- try current = client.getdir(dir.getText());
- catch(RequestException e) {
- new ErrorWindow("Couldn't access "+dir.getText()+" : "+
- e.getMessage());
- dir.setText(client.currentdir);
- return;
- }
- client.currentdir = dir.getText();
- files.clear();
- filesinfo.removeAllElements();
- versions.clear();
- versionsinfo.removeAllElements();
- users.clear();
- usersinfo.removeAllElements();
- file.setText("");
- for(int i=0; i<current.size(); i++) {
- JFSfile f = (JFSfile)current.files.elementAt(i);
- filesinfo.addElement(f);
- files.addItem(f.name, f.type);
- }
- }
-
- // fillversion
- // Fill the versions list with all the versions of the current file
- void fillversions(JFSfile fl)
- {
- versions.clear();
- versionsinfo.removeAllElements();
- if (fl.multiversion) {
- for(int i=0; i<fl.versions.size(); i++) {
- JFSversion vr = (JFSversion)fl.versions.elementAt(i);
- versions.addItem(String.valueOf(vr.number),
- String.valueOf(vr.size));
- versionsinfo.addElement(vr);
- }
- vpurb.enable();
- }
- else {
- JFSversion vr = (JFSversion)fl.versions.elementAt(0);
- versions.addItem("Single",String.valueOf(vr.size));
- versionsinfo.addElement(vr);
- vpurb.disable();
- }
- versions.select(versionsinfo.size()-1);
- }
-
- // fillusers
- // Fill the users list with all the users able to access the current
- // file.
- void fillusers(JFSfile fl)
- {
- users.clear();
- usersinfo.removeAllElements();
- for(int i=0; i<fl.users.size(); i++) {
- JFSfileuser us = (JFSfileuser)fl.users.elementAt(i);
- String acc = "";
- if (us.rwp.indexOf('r') != -1) acc += "Read ";
- if (us.rwp.indexOf('w') != -1) acc += "Write ";
- if (us.rwp.indexOf('p') != -1) acc += "Chmod ";
- users.addItem(us.name, acc);
- usersinfo.addElement(us);
- }
- }
-
- // connect
- // Connect to the given JFS server
- void connect(JFSclient c)
- {
- super.connect(c);
- dir.setText(client.currentdir);
- fillfiles();
- try if (!client.canaccess("/dev/Printer", 'w')) fprintb.disable();
- catch(RequestException e);
- }
-
- // wantedsize
- Dimension wantedsize()
- {
- return new Dimension(600, 400);
- }
-
- // action
- // Handle input from the user
- public boolean action(Event evt, Object obj)
- {
- String arg = (String)evt.arg;
- if (evt.target == files && arg.equals("Single")) {
- // single click on filename
- int sel = files.selected();
- JFSfile selfl = (JFSfile)filesinfo.elementAt(sel);
- file.setText(selfl.name);
- fillversions(selfl);
- fillusers(selfl);
- }
- else if (evt.target == pathb) {
- // Refresh directory button clicked
- fillfiles();
- }
- else if (evt.target == parb) {
- // Parent button clicked
- String d = dir.getText();
- if (!d.equals("/")) {
- d = d.substring(0, d.lastIndexOf('/'));
- dir.setText(d.length() == 0 ? "/" : d);
- fillfiles();
- }
- }
- else if (evt.target == fopenb ||
- evt.target == files && arg.equals("Double") ||
- evt.target == versions && arg.equals("Double")) {
- // File chosen by double-click, or click on Open
- int s = files.selected();
- if (s < 0) return true; // nothing chosen
- JFSfile selfl = (JFSfile)filesinfo.elementAt(s);
- if (selfl.type.equals("jfs/directory")) {
- // enter a new dir
- String cd = dir.getText();
- dir.setText(cd + (cd.equals("/") ? "" : "/") +
- selfl.name);
- fillfiles();
- }
- else {
- // find and start handler program
- String handler = null;
- try handler = client.gethandler(selfl.type);
- catch(RequestException e) {
- new ErrorWindow("Error getting handler for "+
- selfl.name + " : " +
- e.getMessage());
- return true;
- }
- if (handler != null) {
- String full = dir.getText()+"/"+file.getText();
- int v = ((JFSversion)versionsinfo.elementAt(
- versions.selected())).number;
- new ProgramWindow(handler, client, ap, full, v);
- }
- }
- }
- else if (evt.target == frunb) {
- // Run program button clicked
- new ProgramChooser(client, ap);
- }
- else if (evt.target == fdelb) {
- // Delete file button clicked
- int s = files.selected();
- if (s < 0) return true; // nothing chosen
- JFSfile selfl = (JFSfile)filesinfo.elementAt(s);
- try client.delete(dir.getText()+"/"+selfl.name, 0);
- catch(RequestException e)
- new ErrorWindow("Couldn't delete "+selfl.name+" : "+
- e.getMessage());
- fillfiles();
- }
- else if (evt.target == fcopyb && copyreq == null) {
- // Copy button clicked
- copyreq = new FilenameReq(this,"Destination",dir.getText()+"/");
- }
- else if (evt.target == copyreq) {
- // Destination file for copy chosen
- if (arg != null) {
- int s = files.selected();
- if (s < 0) return true; // nothing chosen
- JFSfile selfl = (JFSfile)filesinfo.elementAt(s);
- try client.copy(dir.getText()+"/"+selfl.name,
- copyreq.getFile());
- catch(RequestException e)
- new ErrorWindow("Couldn't copy "+selfl.name+
- " : "+e.getMessage());
- fillfiles();
- }
- copyreq = null;
- }
- else if (evt.target == frenb && renreq == null) {
- // Rename button clicked
- renreq = new FilenameReq(this, "New name", dir.getText()+"/");
- }
- else if (evt.target == renreq) {
- // Destination file for rename chosen
- if (arg != null) {
- int s = files.selected();
- if (s < 0) return true; // nothing chosen
- JFSfile selfl = (JFSfile)filesinfo.elementAt(s);
- try client.rename(dir.getText()+"/"+selfl.name,
- renreq.getFile());
- catch(RequestException e)
- new ErrorWindow("Couldn't copy "+selfl.name+
- " : "+e.getMessage());
- fillfiles();
- }
- renreq = null;
- }
- else if (evt.target == fmkdirb && mkdirreq == null) {
- // Make dir button clicked
- mkdirreq = new FilenameReq(this,"Directory to create","");
- }
- else if (evt.target == mkdirreq) {
- // Directory to make chosen
- if (arg != null) {
- try client.mkdir(dir.getText()+"/"+arg);
- catch(RequestException e) {
- new ErrorWindow("Couldn't make directory "+
- arg+" : "+e.getMessage());
- return true;
- }
- fillfiles();
- }
- mkdirreq = null;
- }
- else if (evt.target == fprintb) {
- // Print button clicked. Find and load a handler for the
- // the chosen file that knows how to print it.
- int s = files.selected();
- if (s < 0) return true; // nothing chosen
- JFSfile selfl = (JFSfile)filesinfo.elementAt(s);
- String handler = null;
- try handler = client.gethandler(selfl.type);
- catch(RequestException e) {
- new ErrorWindow("Error getting handler to print "+
- selfl.name + " : " + e.getMessage());
- return true;
- }
- if (handler != null) {
- String full = dir.getText()+"/"+file.getText();
- int v = ((JFSversion)versionsinfo.elementAt(
- versions.selected())).number;
- JFScomponent cmp = null;
- try {
- Class hc = Class.forName(handler);
- cmp = (JFScomponent)hc.newInstance();
- }
- catch(Exception e) {
- new ErrorWindow(handler+" couldn't load "+
- selfl.name+" for printing : "+
- e.getMessage());
- return true;
- }
- cmp.connect(client);
- try cmp.load(full, v);
- catch(RequestException e) {
- new ErrorWindow("Error loading "+selfl.name+
- " for printing : "+
- e.getMessage());
- return true;
- }
- new PrintRequestor(cmp, client);
- }
- }
- else if (evt.target == fchtypeb && chtypereq == null) {
- // Change MIME type button clicked. Open type requestor
- int s = files.selected();
- if (s < 0) return true; // nothing chosen
- JFSfile selfl = (JFSfile)filesinfo.elementAt(s);
- chtypereq = new FilenameReq(this, "New MIME type", selfl.type);
- }
- else if (evt.target == chtypereq) {
- // MIME type chosen
- if (arg != null) {
- int s = files.selected();
- if (s < 0) return true; // nothing chosen
- JFSfile selfl = (JFSfile)filesinfo.elementAt(s);
- try client.chtype(dir.getText()+"/"+selfl.name,
- chtypereq.getFile());
- catch(RequestException e)
- new ErrorWindow("Could change the type of "+
- selfl.name+" : "+
- e.getMessage());
- fillfiles();
- }
- chtypereq = null;
- }
- else if (evt.target == uinfob ||
- evt.target == users && arg.equals("Double")) {
- // User chosen by double-click, or click on Open
- int sel = users.selected();
- if (sel < 0) return true; // no user chosen
- JFSfileuser fu = (JFSfileuser)usersinfo.elementAt(sel);
- try {
- JFSuser u = client.uinfo(fu.name);
- new UserWindow(u);
- return true;
- }
- catch(RequestException e);
- // this must be a group then..
- Vector uv = null;
- try uv = client.ginfo(fu.name);
- catch(RequestException e) {
- new ErrorWindow(e.getMessage());
- return true;
- }
- new GroupWindow(fu.name, uv);
- }
- else if (evt.target == uaddb && !file.getText().equals("")) {
- // File user add button chosen
- new UserAddReq(this, dir.getText()+"/"+file.getText(), client);
- }
- else if (evt.target == udelb) {
- // Delete user button clicked
- int sel = users.selected();
- if (sel < 0) return true; // no user chosen
- try client.chmod(dir.getText()+"/"+file.getText(),
- ((JFSfileuser)usersinfo.elementAt(sel)).name,
- null);
- catch(RequestException e)
- new ErrorWindow("Couldn't delete user : "+
- e.getMessage());
- fillfiles();
- }
- else if (evt.target == vdelb) {
- // Version delete button clicked
- int sel = versions.selected();
- if (sel < 0) return true; // no version chosen
- JFSfile selfl = (JFSfile)filesinfo.elementAt(files.selected());
- JFSversion selvr = (JFSversion)versionsinfo.elementAt(sel);
- int ver = selfl.multiversion ? selvr.number : 0;
- try client.delete(dir.getText()+"/"+selfl.name, ver);
- catch(RequestException e)
- new ErrorWindow("Couldn't delete version : "+
- e.getMessage());
- fillfiles();
- }
- else if (evt.target == vpurb) {
- // Version purge button clicked
- int s = files.selected();
- if (s < 0) return true; // nothing chosen
- JFSfile selfl = (JFSfile)filesinfo.elementAt(s);
- try client.purge(dir.getText()+"/"+selfl.name);
- catch(RequestException e)
- new ErrorWindow("Couldn't purge "+selfl.name+" : "+
- e.getMessage());
- fillfiles();
- }
- else if (evt.target == vinfob) {
- // Version info button clicked
- int sel = versions.selected();
- if (sel < 0) return true; // no version chosen
- JFSfile selfl = (JFSfile)filesinfo.elementAt(files.selected());
- JFSversion selvr = (JFSversion)versionsinfo.elementAt(sel);
- new VersionInfoWindow(selfl, selvr);
- }
- return true;
- }
- }
-
- // ProgramWindow
- // Given a class name, loads that class (which must be a subclass of
- // JFScomponent) and intantiates it in a top level window of it's own.
- // The connect method of the loaded class is called with the given JFSclient,
- // to connect it to a JFS server.
- // If a filename and version are given as well, calls the load method of the
- // component with the given file.
- // If anything goes wrong, an error message window is displayed.
- class ProgramWindow extends FixedFrame
- {
- JFScomponent cmp;
- JFSclient programclient;
-
- ProgramWindow(String pclass, JFSclient client, java.applet.Applet a)
- {
- init(pclass, client, a);
- setsize(cmp.wantedsize());
- setTitle(cmp.getClass().getName());
- pack();
- show();
- }
-
- ProgramWindow(String pclass, JFSclient client, java.applet.Applet a,
- String f, int v)
- {
- if (!init(pclass, client, a))
- return;
- try cmp.load(f, v);
- catch(RequestException e) {
- new ErrorWindow(pclass+" couldn't load "+
- f+" : "+e.getMessage());
- return;
- }
- setsize(cmp.wantedsize());
- setTitle(cmp.getClass().getName() + " - " +
- f.substring(f.lastIndexOf('/')+1));
- pack();
- show();
- }
-
- // init
- // Load and instantiate the given class in this window.
- // Returns true if successful, false otherwise
- boolean init(String pclass, JFSclient client, java.applet.Applet a)
- {
- try {
- Class hc = Class.forName(pclass);
- cmp = (JFScomponent)hc.newInstance();
- }
- catch(ClassNotFoundException e) {
- new ErrorWindow("Program class not found");
- return false;
- }
- catch(InstantiationException e) {
- new ErrorWindow("Could not instantiate "+
- "program class");
- return false;
- }
- catch(IllegalAccessException e) {
- new ErrorWindow("Illegal access to program "+
- "class");
- return false;
- }
- catch(ClassCastException e) {
- new ErrorWindow("Not a valid program class");
- return false;
- }
- cmp.init(a);
- try cmp.connect(programclient = client.newclient());
- catch(RequestException e) {
- new ErrorWindow("Failed to make new connection to server");
- return false;
- }
- setLayout(new BorderLayout());
- add("Center",cmp);
- return true;
- }
-
- public boolean handleEvent(Event evt)
- {
- if (evt.id == Event.WINDOW_DESTROY) {
- programclient.close();
- dispose();
- }
- return super.handleEvent(evt);
- }
- }
-
- // FilenameReq
- // A request for entering a single filename, for the stuff like copying,
- // renaming and so on.
- class FilenameReq extends FixedFrame
- {
- Component parent;
- TextField name;
- Button ok, can;
-
- FilenameReq(Component p, String l, String n)
- {
- super(new Dimension(250, -1));
- parent = p;
- setLayout(new BorderLayout());
- Panel top = new Panel();
- top.setLayout(new BorderLayout());
- top.add("West",new Label(l));
- top.add("Center",name = new TextField(n));
- add("North",top);
- Panel bot = new Panel();
- bot.setLayout(new FlowLayout(FlowLayout.RIGHT));
- bot.add(ok = new Button("Ok"));
- bot.add(can = new Button("Cancel"));
- add("South",bot);
- setTitle(l);
- pack();
- show();
- }
-
- // getFile
- // Returns the name of the file chosen by the user
- String getFile()
- {
- return name.getText();
- }
-
- public boolean handleEvent(Event evt)
- {
- if (evt.id == Event.WINDOW_DESTROY ||
- evt.id == Event.ACTION_EVENT && evt.target == can) {
- dispose();
- parent.postEvent(new Event(this, Event.ACTION_EVENT, null));
- }
- else if (evt.id == Event.ACTION_EVENT &&
- (evt.target == ok || evt.target == name)) {
- dispose();
- parent.postEvent(new Event(this, Event.ACTION_EVENT,
- name.getText()));
- }
- return super.handleEvent(evt);
- }
- }
-
-
- // ProgramChooser
- // A window containing a list of mime types and handler programs. When
- // one is chosen by the user, the given handler program is run in a window
- // of it's own.
- class ProgramChooser extends FixedFrame
- {
- JFSclient client;
- DoubleListPanel list;
- Button close;
- Vector progs = new Vector();
- java.applet.Applet ap;
-
- ProgramChooser(JFSclient c, java.applet.Applet a)
- {
- super(new Dimension(300,300));
- // create interface
- ap = a;
- client = c;
- String str = "Select program to run";
- setLayout(new BorderLayout());
- add("North",new Label(str));
- add("Center",list = new DoubleListPanel("Program","Mime type"));
- Panel bot = new Panel();
- bot.setLayout(new FlowLayout(FlowLayout.RIGHT));
- bot.add(close = new Button("Close"));
- add("South",bot);
- setTitle(str);
-
- // Fill list with known programs
- Vector ty = new Vector();
- try client.getprograms(progs, ty);
- catch(RequestException e) {
- new ErrorWindow("Couldn't read handlers file : "+
- e.getMessage());
- return;
- }
- for(int i=0; i<progs.size(); i++) {
- String hprog = (String)progs.elementAt(i);
- boolean already = false;
- for(int j=0; j<i; j++)
- if (((String)progs.elementAt(i)).equals(
- (String)progs.elementAt(j)))
- already = true;
- if (!already) {
- MimeType htype = (MimeType)ty.elementAt(i);
- list.addItem(hprog, htype == null ? "" :
- htype.toString());
- }
- else {
- progs.removeElementAt(i);
- ty.removeElementAt(i);
- i--;
- }
- }
- pack();
- show();
- }
-
- public boolean handleEvent(Event evt)
- {
- if (evt.id == Event.WINDOW_DESTROY ||
- evt.id == Event.ACTION_EVENT && evt.target == close)
- dispose();
- else if (evt.id == Event.ACTION_EVENT && evt.target == list &&
- ((String)evt.arg).equals("Double")) {
- // run the chosen program
- new ProgramWindow((String)progs.elementAt(list.selected()),
- client, ap);
- dispose();
- }
- return super.handleEvent(evt);
- }
- }
-
-
- // UserWindow
- // Displays infomation about a given user.
- class UserWindow extends FixedFrame
- {
- Button close;
-
- UserWindow(JFSuser u)
- {
- super(new Dimension(300, -1));
- GridBagConstraints leftc = new GridBagConstraints(),
- rightc = new GridBagConstraints();
- leftc.fill = GridBagConstraints.BOTH;
- rightc.gridwidth = GridBagConstraints.REMAINDER;
- rightc.weightx = 1;
- rightc.fill = GridBagConstraints.BOTH;
-
- // create user details panel
- GridBagLayout topl = new GridBagLayout();
- setLayout(new BorderLayout());
- Panel top = new Panel();
- top.setLayout(topl);
- Label l1, l2, l3;
- StaticTextField s1, s2, s3;
- top.add(l1 = new Label("Username"));
- topl.setConstraints(l1, leftc);
- top.add(s1 = new StaticTextField(u.name));
- topl.setConstraints(s1, rightc);
- top.add(l2 = new Label("Real name"));
- topl.setConstraints(l2, leftc);
- top.add(s2 = new StaticTextField(u.realname));
- topl.setConstraints(s2, rightc);
- top.add(l3 = new Label("Home dir"));
- topl.setConstraints(l3, leftc);
- top.add(s3 = new StaticTextField(u.home));
- topl.setConstraints(s3, rightc);
-
- Panel left = new Panel();
- left.setLayout(new BorderLayout());
- left.add("North",new Label("Groups"));
- top.add(left);
- topl.setConstraints(left, leftc);
-
- List glist = new List();
- glist.addItem("all");
- for(int i=0; i<u.groups.size(); i++)
- glist.addItem((String)u.groups.elementAt(i));
- top.add(glist);
- rightc.gridheight = GridBagConstraints.REMAINDER;
- rightc.weighty = 1;
- topl.setConstraints(glist, rightc);
-
- add("Center",top);
-
- // create close button panel
- Panel bot = new Panel();
- bot.setLayout(new FlowLayout(FlowLayout.RIGHT));
- bot.add(close = new Button("Close"));
- add("South",bot);
-
- setTitle(u.name);
- pack();
- show();
- }
-
- public boolean handleEvent(Event evt)
- {
- if (evt.id == Event.WINDOW_DESTROY ||
- evt.id == Event.ACTION_EVENT && evt.target == close)
- dispose();
- return super.handleEvent(evt);
- }
- }
-
- // GroupWindow
- // A window displaying information about a JFS group
- class GroupWindow extends FixedFrame
- {
- Button close;
-
- GroupWindow(String name, Vector users)
- {
- super(new Dimension(300, -1));
- // create group name panel
- setLayout(new BorderLayout());
- Panel top = new Panel();
- top.setLayout(new GridLayout(1,2));
- top.add(new Label("Groupname", Label.RIGHT));
- top.add(new StaticTextField(name));
- add("North",top);
-
- // create group members panel
- Panel mid = new Panel();
- mid.setLayout(new GridLayout(1,2));
- Panel left = new Panel();
- left.setLayout(new BorderLayout());
- left.add("North",new Label("Members", Label.RIGHT));
- mid.add(left);
- List ulist;
- mid.add(ulist = new List());
- for(int i=0; i<users.size(); i++)
- ulist.addItem((String)users.elementAt(i));
- add("Center",mid);
-
- // create close panel
- Panel bot = new Panel();
- bot.setLayout(new FlowLayout(FlowLayout.RIGHT));
- bot.add(close = new Button("Close"));
- add("South",bot);
-
- setTitle(name);
- pack();
- show();
- }
-
- public boolean handleEvent(Event evt)
- {
- if (evt.id == Event.WINDOW_DESTROY ||
- evt.id == Event.ACTION_EVENT && evt.target == close)
- dispose();
- return super.handleEvent(evt);
- }
- }
-
- // UserAddReq
- // A window for entering details of a user/group to give permissions to a file
- class UserAddReq extends FixedFrame
- {
- FileBrowserComponent parent;
- String file;
- JFSclient client;
- TextField user;
- Checkbox read, write ,perms;
- Button ok, can;
-
- UserAddReq(FileBrowserComponent p, String f, JFSclient c)
- {
- super(new Dimension(350, -1));
- parent = p;
- file = f;
- client = c;
- setLayout(new BorderLayout());
-
- // Create panel with name and permission setting controls
- Panel top = new Panel();
- GridBagConstraints leftc = new GridBagConstraints(),
- rightc = new GridBagConstraints();
- leftc.fill = GridBagConstraints.BOTH;
- rightc.gridwidth = GridBagConstraints.REMAINDER;
- rightc.weightx = 1;
- rightc.fill = GridBagConstraints.BOTH;
- GridBagLayout topl = new GridBagLayout();
- top.setLayout(topl);
- Label l1, l2, l3;
- StaticTextField s1;
- Panel p1;
- top.add(l1 = new Label("Filename"));
- topl.setConstraints(l1, leftc);
- top.add(s1 = new StaticTextField(f));
- topl.setConstraints(s1, rightc);
- top.add(l2 = new Label("User/group to add"));
- topl.setConstraints(l2, leftc);
- top.add(user = new TextField());
- topl.setConstraints(user, rightc);
- top.add(l3 = new Label("Permissions"));
- topl.setConstraints(l3, leftc);
- Panel pch = new Panel();
- pch.setLayout(new FlowLayout(FlowLayout.LEFT));
- pch.add(read = new Checkbox("Read"));
- pch.add(write = new Checkbox("Write"));
- pch.add(perms = new Checkbox("Chmod"));
- top.add(pch);
- rightc.gridheight = GridBagConstraints.REMAINDER;
- rightc.weighty = 1;
- topl.setConstraints(pch, rightc);
- add("North",top);
-
- // Create panel with ok and cancel buttons
- Panel bot = new Panel();
- bot.setLayout(new FlowLayout(FlowLayout.RIGHT));
- bot.add(ok = new Button("OK"));
- bot.add(can = new Button("Cancel"));
- add("South",bot);
-
- setTitle("File permissions");
- pack();
- show();
- }
-
- public boolean handleEvent(Event e)
- {
- if (e.id == Event.WINDOW_DESTROY ||
- e.id == Event.ACTION_EVENT && e.target == can)
- dispose();
- else if (e.id == Event.ACTION_EVENT && e.target == ok) {
- // do the permission change
- try client.chmod(file, user.getText(),
- (read.getState() ? "r" : "")+
- (write.getState() ? "w" : "")+
- (perms.getState() ? "p" : ""));
- catch(RequestException ex)
- new ErrorWindow("Couldn't set permissions : "+
- ex.getMessage());
- dispose();
- parent.fillfiles();
- }
- return super.handleEvent(e);
- }
- }
-
-
- // StaticTextField
- // A text field that is set to be non-editable by default
- class StaticTextField extends TextField
- {
- StaticTextField()
- {
- super();
- setEditable(false);
- }
-
- StaticTextField(String s)
- {
- super(s);
- setEditable(false);
- }
-
- StaticTextField(String s, int i)
- {
- super(s,i);
- setEditable(false);
- }
- }
-
- // VersionInfoWindow
- // A pop-up window displaying information about a version of a file
- class VersionInfoWindow extends FixedFrame
- {
- Button close;
-
- VersionInfoWindow(JFSfile f, JFSversion v)
- {
- super(300, -1);
- // create UI
- setLayout(new BorderLayout());
- Panel left = new Panel();
- left.setLayout(new GridLayout(5,1));
- left.add(new Label("Filename"));
- left.add(new Label("Version"));
- left.add(new Label("Size"));
- left.add(new Label("Creator"));
- left.add(new Label("Time"));
- add("West", left);
- Panel right = new Panel();
- right.setLayout(new GridLayout(5,1));
- right.add(new StaticTextField(f.name));
- right.add(new StaticTextField(String.valueOf(v.number)));
- right.add(new StaticTextField(String.valueOf(v.size)));
- right.add(new StaticTextField(v.creator));
- right.add(new StaticTextField(new Date(v.time).toString()));
- add("Center", right);
- Panel bot = new Panel();
- bot.setLayout(new FlowLayout(FlowLayout.RIGHT));
- bot.add(close = new Button("Close"));
- add("South", bot);
-
- setTitle("Version info");
- pack();
- show();
- }
-
- public boolean action(Event evt, Object obj)
- {
- if (evt.target == close)
- dispose();
- return true;
- }
- }
-
-